const $ = (function () {
    const getStyle = (obj, attr) => {
        if (window.getComputedStyle) {
            return window.getComputedStyle(obj, null)[attr];
        }
        return obj.currentStyle[attr]
    }

    const animate = (oEle, json, callback) => {
        clearInterval(oEle.timer);
        oEle.timer = setInterval(() => {
            let flag = true;
            for (let attr in json) {
                let current = 0;//当前位置
                let target = 0;// 目标值
                if (attr === "opacity") {
                    current = parseFloat(getStyle(oEle, attr)) * 100;
                    target = parseFloat(json[attr]) * 100;
                } else {
                    current = parseInt(getStyle(oEle, attr))
                    target = parseInt(json[attr]);
                }
                //(目标-当前值 )/10
                let steps = (target - current) / 10;
                steps = steps > 0 ? Math.ceil(steps) : Math.floor(steps);
                if (attr === 'opacity') {
                    oEle.style.opacity = (current + steps) / 100;
                    //ie 6的透明  0~100
                    oEle.style.filter = `alpha(opacity=${(current + steps)})`
                } else if (attr == 'zIndex') {
                    oEle.style.zIndex = target;
                } else {
                    oEle.style[attr] = (current + steps) + 'px'
                }

                if (current != target) {
                    flag = false;
                }
            }

            if (flag) {
                clearInterval(oEle.timer);
                if (typeof callback == "function") {
                    callback();
                }
            }
        }, 30);
    }

    return {
        getStyle,
        animate
    }

})()